<template>
  <!--  登录表单容器-->
  <div class="login_container">
    <!--      登录区域-->
    <div class="login_box">
      <!--        头像-->
      <div class="avatar_box">
        <img src="../assets/img/9e3df8dcd100baa1a5fd20114d10b912c9fc2e42.jpg">
      </div>
      <!--        表单-->

      <el-form :model="loginForm" :rules="rules" ref="loginForm" label-width="0px" class="login_form">
        <el-form-item prop="username">
          <el-input prefix-icon="el-icon-user" v-model="loginForm.username"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input prefix-icon="el-icon-lock" v-model="loginForm.password"></el-input>
        </el-form-item>
        <el-form-item prop="verifyCode">
          <div class="verifyCode_box">
            <el-input prefix-icon="el-icon-mobile" placeholder="请输入手机验证码" v-model="loginForm.verifyCode"
                      class="verify_code"></el-input>
            <img src="" class="verify_img">
          </div>
        </el-form-item>
        <el-form-item class="logn_btn">
          <el-button type="primary" @click="submitForm('loginForm')">登录</el-button>
          <el-button @click="resetForm('loginForm')">重置</el-button>
        </el-form-item>
      </el-form>

    </div>
  </div>
</template>

<script>
  export default {
    name: '',
    data() {
      return {
        loginForm: {
          username: '',
          password: ''
        },
        rules: {
          username: [
            {required: true, message: '请输入登录名称', trigger: 'blur'},
            {min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur'}
          ],
          password: [
            {required: true, message: '请输入登录密码', trigger: 'blur'},
            {min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur'}
          ],
          verifyCode: [
            {required: true, message: '请输入验证码', trigger: 'blur'}
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$router.push("/main");
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style scoped lang="less">
  .login_container {
    height: 100%;
    background-color: #42b983;
  }

  .login_box {
    width: 450px;
    height: 380px;
    background-color: #FFFFFF;
    border-radius: 3px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);

    .avatar_box {
      width: 130px;
      height: 130px;
      border: 1px solid #eeeeee;
      border-radius: 50%;
      padding: 10px;
      box-shadow: 0 2px 12px 0 rgb(0, 0, 0, 0.1);
      margin: -65px auto;
      background-color: #FFFFFF;

      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: #eeeeee;
      }
    }

    .login_form {
      position: absolute;
      bottom: 0px;
      width: 100%;
      padding: 0px 20px;
      box-sizing: border-box;

      .logn_btn {
        display: flex;
        justify-content: flex-end;
      }

      .verifyCode_box {
        display: flex;

        .verify_code {
          width: 60%;
        }

        .verify_img {
          background-size: contain;
          width: 60%;
        }
      }
    }

  }
</style>
